package com.lmt.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Date 2018/06/27
 *
 * @author MT-Lin
 */
@RestController
public class MetadataController {

    private final DiscoveryClient discoveryclient;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    public MetadataController(DiscoveryClient discoveryclient) {
        this.discoveryclient = discoveryclient;
    }

    @GetMapping("/getMetadata")
    public List<ServiceInstance> getMetadata() {
        logger.warn("provider-my-metadata->getMetadata");
        return discoveryclient.getInstances("provider-my-metadata");
    }
}
